list1 = [1, 2, "111", 3]
length = len(list1)
for each in list1:
    print(each)
print(list1[-1])
# 此处符号的意义为从后往前数
print(list1[0:3:1])
# 开头或末尾可省略，如[::2]代表从头到尾，跨度值为2
list1.append("4")
list1[len(list1):] = "4"
# 上面两种写法意义相同
print(list1)
list1.extend([1, 2, 3])
# 利用extend函数来插入数组
print(list1)
# 在指定位置插入需要用到insert方法
list1.insert(0, 2)
print(list1)
# 列表删除用到remove和pop方法,且只会删除一个
list1.remove(2)
print(list1)
list1.pop(2)
print(list1)
# 清空列表使用clear方法（无参数）
list1.clear()
print(list1)
num = [1, 2, 3, 6, 4]
num.sort()
# 自动排序,sort从小到大，reverse从大到小，参数一栏可以输入布尔类型，正确是按当前方法排序，错误是按相反方法排序
print(num)
''' 冒泡排序
for i in num:
    for j in num:
        if (num[i] > num[j]) and i < j:
            temp = num[i]
            num[i] = num[j]
            num[j] = temp
'''
# 列表查找包括下面两种
num.count(2)
# 此种用来查找具体内容
num.index(2)
# 用来查找对应的索引
num.index(2, 1, 3)
# 三个参数分别是查找的内容，查找的起始索引，查找的末索引
# 拷贝数组
num_Copy = num[1:].copy()
print(num_Copy, "copy end")
""" 判断两者地址值是否相同使用is运算符
x = "111"
y = "111"
print(x is y)
"""
# 创建一个二位列表
num1 = [0] * 3
for i in range(3):
    num1[i] = [0] * 3
print(num1)
# 浅拷贝和深拷贝，浅拷贝即使用copy方法,只拷贝一维数组中的值
copy1 = [1, 2, 3]
copy2 = copy1.copy()
copy1[1] = 0
print(copy1)
print(copy2)
# 当被拷贝数组出现多维数组时就会出现问题
copy3 = [[1, 2, 3], [4, 5, 6], [7, 8, 9]]
copy4 = copy3.copy()
# copy3[1][1] = 0
print(copy3)
print(copy4)
# 深拷贝要用到copy模块
import copy

copy5 = copy.copy(copy3)
copy6 = copy.deepcopy(copy3)
copy3[1][1] = 0
print(copy6)

# 列表推导式，如将列表内元素全部翻倍
cal1 = [1, 2, 3, 4, 5]
for i in range(len(cal1)):
    cal1[i] = cal1[i] * 2
print(cal1)
cal1 = [i * 2 for i in cal1]  # 此种方法是创建新列表
print(cal1)
# ord函数可以将字符串转为内置代码
# 列表推导式格式[express for i in range 判断语句] 判断语句可省略
words = ["one", "two", "three", "four"]
word_O = [words[i] for i in range(len(words)) if words[i][0] == 'o']
# w for w in words if w[0]=='o'与其结果相同
print(word_O)
# 列表嵌套使用列表推导式
cal2 = [[1, 2, 3], [4, 5, 6], [7, 8, 9]]
cal3 = [col for row in cal2 for col in row]
print(cal3)
